# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: T.J. Townsend <blakkheim@archlinux.org>
# Contributor: Vesa Kaihlavirta <vegai@iki.fi>
# Contributor: Mark Rosenstand <mark@borkware.net>
# Contributor: Giorgio Lando <patroclo7@gmail.com> (adjtimex patch)
# Contributor: Alexander Rødseth <rodseth@gmail.com>

pkgname=openntpd
pkgver=6.8p1
pkgrel=5
pkgdesc='Free, easy to use implementation of the Network Time Protocol'
url='https://www.openntpd.org/'
arch=('loong64' 'x86_64')
license=('BSD')
depends=('glibc' 'libressl')
conflicts=('ntp')
backup=('etc/ntpd.conf')
source=(https://cdn.openbsd.org/pub/OpenBSD/OpenNTPD/${pkgname}-${pkgver}.tar.gz{,.asc}
        openntpd.sysusers
        openntpd.service)
sha512sums=('200056bedb9c757aae1ce5d3f6655175ec058cb479429fe4704955f3a3fa15e8a9cb578ae4898ddb4cfc08c9742bbab6a7c92b5e569f06a148e40c448360b58f'
            'SKIP'
            'b6bb4f39eb435ce6c3314ea4a31430a1f8b70898d17d1fe07fa487bec0e79c022b004d3c11366f0f994546f454e5418caf5b3d7e6e1a205598d2bc8140417f7a'
            '15c1a510fa8f43217b6a3fc3ba287176d04fbe0c4bbea616ab08d1c679ed9da6734233b70b4858093992a3fbf4346642353eb2626fd8e5668cda3712d5ea43b7')
validpgpkeys=('A1EB079B8D3EB92B4EBD3139663AF51BD5E4D8D5') # Brent Cook <bcook@openbsd.org>

prepare() {
  cd ${pkgname}-${pkgver}
  autoreconf -fiv
  sed -i 's|pool.ntp.org|2.arch.pool.ntp.org|' ntpd.conf
}

build() {
  cd ${pkgname}-${pkgver}
  CFLAGS+=' -fcommon -I/usr/include/libressl -L/usr/lib/libressl -Wl,-rpath=/usr/lib/libressl' \
    ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --sbindir=/usr/bin \
    --with-privsep-user=ntp \
    --localstatedir=/var
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  rmdir "${pkgdir}/var/run"
  install -d "${pkgdir}/var/lib/ntp"
  install -Dm 644 COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 "${srcdir}/openntpd.service" -t "${pkgdir}/usr/lib/systemd/system"
  install -Dm 644 "${srcdir}/openntpd.sysusers" "${pkgdir}/usr/lib/sysusers.d/openntpd.conf"

  install -d "${pkgdir}/usr/lib/systemd/ntp-units.d"
  echo ${pkgname}.service > "${pkgdir}/usr/lib/systemd/ntp-units.d/${pkgname}.list"
}

# vim: ts=2 sw=2 et:
